﻿<%@ Page Language="C#" MasterPageFile="~/MasterTheme/Auto.master" AutoEventWireup="true"
    Inherits="xIx.Web.Portal.PageBase" Title="Untitled Page" %>

<%@ Register Assembly="xIx.Web.Portal" Namespace="xIx.Web.Portal" TagPrefix="DS" %>
<script runat="server">
    System.Data.DataTable ListSrc = null;
    int RowCount = 0;
    bool IsDocList = false;
    int PageSize = 20;
    string Sid = string.Empty;
    protected void Page_Load(object sender, EventArgs arg)
    {
        if (string.IsNullOrEmpty(Request["ID"])) return;

        IsDocList = (Request["Type"] == "DocLib");

        using (var dh = new xIx.Data.DbHelper())
        {
            System.Data.DataTable dt = null;

            Sid= Request["SID"];
            if (string.IsNullOrEmpty(Sid))
            {
                dt = dh.Table["Sys_Groups"].Where("Pid=@pid").Fields("ID").Select(Request["ID"]);
                if (null != dt && dt.Rows.Count > 0) Sid = dt.Rows[0][0].ToString();
            }

            dt = dh.Table["Sys_ListItems"].Fields("Count(*) Rc").Where("Gid=@gid").Select(Sid);
            if (null != dt && dt.Rows.Count > 0) RowCount = int.Parse(dt.Rows[0][0].ToString());
            int p=0,si = 0, ei = 20;
            int.TryParse(Request["P"],out p);
            si = p * PageSize;
            ei = si + PageSize;
            
            ListSrc = dh.Table["Sys_ListItems"].Fields("ID,Title,Img,AttachFile,ContentTime").Where("Gid=@gid").OrderBy(string.Format( "ContentTime Desc limit {0},{1}",si,ei)).Select(Sid);
            //if (IsDocList)
            //{
            //    RepeaterDoc.DataSource = ListSrc;
            //    RepeaterImg.Visible = false;
            //}
            //else {
            //    RepeaterImg.DataSource = ListSrc;
            //    RepeaterDoc.Visible = false;
            //}

        }
    }
    void LoadData(object sender, SEDataEventArg arg)
    {
        arg.OutDataView = ListSrc.DefaultView;
    }
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <asp:Repeater ID="Repeater1" runat="server" DataSourceID="IS1" EnableViewState="false">
        <ItemTemplate>
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td height="36">
                        <h1>
                            <%# Eval("Title") %>
                        </h1>
                    </td>
                </tr>
                <tr>
                    <td valign="top" style="padding-top: 2px;">
                        <table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                                <td bgcolor="#CAD7E7">
                                    <div align="right">
                                        发布时间：<span><%#Eval("ContentTime","{0:yyyy年MM月dd日}") %></span> 发布人：<span><%#Eval("Editor") %></span>
                                        &nbsp;&nbsp;&nbsp;</div>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td class="text_con">
                        <p>
                            <%# Eval("Text") %>
                        </p>
                    </td>
                </tr>
            </table>
        </ItemTemplate>
    </asp:Repeater>
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td>
                <asp:Repeater runat="server" ID="repeater2" EnableViewState="false" DataSourceID="LS2">
                    <HeaderTemplate>
                        <h2>
                            <strong>专题库：</strong></h2>
                        <table cellspacing="0" width="100%" class="Zhuanti">
                            <tr>
                                <td class="separator">
                                    &nbsp;
                                </td>
                    </HeaderTemplate>
                    <ItemTemplate>
                        <td class='<%# Request["SID"]==Eval("ID").ToString()?"active":"deactive" %>'>
                            <asp:HyperLink runat="server" ID="hyperlink2" Text='<%#Eval("Title") %>' NavigateUrl='<%# string.Format("ZhuanTi.Aspx?ID={0}&SID={1}&Type={2}",Request["ID"],Eval("ID"),"救援成果"==Eval("Title").ToString()?"DocLib":"ImgLib") %>'></asp:HyperLink>
                        </td>
                    </ItemTemplate>
                    <SeparatorTemplate>
                        <td class="separator">
                            &nbsp;
                        </td>
                    </SeparatorTemplate>
                    <FooterTemplate>
                        <td class="separator space">
                            &nbsp;
                        </td>
                        </tr></table></FooterTemplate>
                </asp:Repeater>
            </td>
        </tr>
        <tr>
            <td style="border: 1px solid #1e4aa3; border-top: none;" align="center">
                <asp:Repeater ID="RepeaterDoc" runat="server" DataSourceID="ES" Visible='<%# IsDocList %>'>
                    <HeaderTemplate>
                        <div style="padding-left: 24px">
                            <table width="90%" border="0" cellpadding="0" cellspacing="0" class="news-list">
                    </HeaderTemplate>
                    <ItemTemplate>
                        <tr>
                            <td>
                                <asp:HyperLink ID="h1" runat="server" NavigateUrl='<%#Eval("AttachFile") %>' Target="_blank"
                                    Text='<%# Eval("Title") %>'></asp:HyperLink>
                            </td>
                            <td>
                                <%# Eval("ContentTime","{0:yyyy-MM-dd}") %>
                            </td>
                        </tr>
                    </ItemTemplate>
                    <AlternatingItemTemplate>
                        <tr class="altrow">
                            <td>
                                <asp:HyperLink ID="h1" runat="server" NavigateUrl='<%#Eval("AttachFile") %>' Target="_blank"
                                    Text='<%# Eval("Title") %>'></asp:HyperLink>
                            </td>
                            <td>
                                <%# Eval("ContentTime", "{0:yyyy-MM-dd}")%>
                            </td>
                        </tr>
                    </AlternatingItemTemplate>
                    <FooterTemplate>
                        </table> </div>
                    </FooterTemplate>
                </asp:Repeater>
                <asp:Repeater ID="RepeaterImg" runat="server" DataSourceID="ES" Visible='<%# !IsDocList %>'>
                    <ItemTemplate>
                        <div class="libimage">
                            <div>
                                <asp:HyperLink runat="server" ID="img1" ImageUrl='<%# Eval("AttachFile")+".thumb.png" %>' NavigateUrl='<%# Eval("AttachFile") %>'
                                    BorderStyle="None" Target="_blank"></asp:HyperLink>
                                <h3>
                                    <%#Eval("Title") %></h3>
                            </div>
                        </div>
                    </ItemTemplate>
                </asp:Repeater>
            </td>
        </tr>
        <tr><td>
            <% var pc = (int)(Math.Ceiling( (double)RowCount / PageSize));
               if (pc > 1)
               {
                   for (int i = 0; i < pc; i++)
                   {
                       Response.Write(string.Format("<a href='{0}?ID={1}&SID={2}&Type={3}&P={4}'>[{5}]</a>&nbsp;&nbsp;", Request.Path, Request["ID"], Sid, Request["Type"],i, i+1));
                   }
               }%>
        </td></tr>
    </table>
    <DS:IS ID="IS1" runat="server" ItemID="#ID" Fields="*">
    </DS:IS>
    <DS:LS ID="LS2" runat="server" GroupID="#ID" Fields="ID,Title" SrcType="Group">
    </DS:LS>
    <DS:SimpleEventDS runat="server" ID="ES" OnOnLoadingData="LoadData">
    </DS:SimpleEventDS>
</asp:Content>
